#include <cassert>

#include <logger.h>
#include <napi_call.h>
#include <node_api.h>

/* napi_value */
NAPI_MODULE_INIT(/* napi_env env, napi_value exports */)
{
    napi_value value = nullptr;
    napi_value key = nullptr;
    assert(napi_get_property(env, exports, key, &value) == napi_invalid_arg);

    const napi_extended_error_info *errinfo = nullptr;
    assert(napi_get_last_error_info(env, &errinfo) == napi_ok);
    VALUE_LOGGER(errinfo->error_message); // Invalid argument
    VALUE_LOGGER(errinfo->engine_reserved); // 0
    VALUE_LOGGER(errinfo->engine_error_code); // 0
    VALUE_LOGGER(errinfo->error_code); // 1
    VALUE_LOGGER((errinfo->error_code == napi_invalid_arg)); // true

    NAPI_CALL(env, napi_get_property(env, exports, key, &value));
    // node:internal/modules/cjs/loader:1183
    //   return process.dlopen(module, path.toNamespacedPath(filename));
    //                  ^
    // 
    // Error: Invalid argument
    //     at Object.Module._extensions..node (node:internal/modules/cjs/loader:1183:18)
    //     at Module.load (node:internal/modules/cjs/loader:975:32)
    //     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    //     at Module.require (node:internal/modules/cjs/loader:999:19)
    //     at require (node:internal/modules/cjs/helpers:102:18)
    //     at [stdin]:1:14
    //     at Script.runInThisContext (node:vm:129:12)
    //     at Object.runInThisContext (node:vm:305:38)
    //     at node:internal/process/execution:76:19
    //     at [stdin]-wrapper:6:22
    // 
    // Node.js v17.7.1
    return exports;
}
